<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>计算考试总成绩</title>
    </head>
    <body>
        <script type="text/javascript">
            function subject() {
                var count=prompt("请输入考试科目数","");
                var sum=0;
                if(count<=0){
                    alert("数量不能是负数或0");
                }else if (isNaN(count)){
                    alert("输入的不是数字");
                }else {
                    for (var i = 1; i<=parseInt(count) ; i++) {
                        var score=prompt("请输入第"+i+"门科目成绩","");
                        if(score<=0){
                            alert("成绩不能是负数");
                            break;
                        }else if (isNaN(score)){
                            alert("输入的不是数字");
                            break;
                        }
                        sum=sum+parseFloat(score);
                    }
            
        
                    alert(count+"门科目的总成绩是："+sum);
                }
            }
        </script>
        <input type="button" value="统计考试总成绩" onclick="subject()"/>
    </body>
</html>